package com.aaa.product.controller;

import com.aaa.entity.Product;
import com.aaa.product.service.IProductService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: qy156-shop-parent
 * @description:
 * @author: 闫克起2
 * @create: 2022-11-17 16:24
 **/
@RestController
@RequestMapping("product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping("/getById/{pid}")
    @SentinelResource("hot") //如果使用热点参数限流 默认对springmvc资源无效。
    public Product getById(@PathVariable Long pid){

        if(pid==1){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return productService.findById(pid);
    }


    @Value("${student.name}")
    private String name;

    @GetMapping("getInfo")
    public String getInfo(){
         return "姓名:"+name;
    }


    @GetMapping("write")
    public String write(){
        return "写的业务";
    }

    @GetMapping("read")
    public String read(){
        return "读的业务";
    }
}
